package com.fulu.game.bi.controller.value;

import com.fulu.game.bi.entity.bo.channel.ValueAddUserConsumeListBO;
import com.fulu.game.bi.entity.dto.UserConsumerListDTO;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.redis.service.value.ValueAddUserConsumeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 增值-用户消费
 */
@RestController
@RequestMapping("/api/value/user/consumer")
@Slf4j
public class UserConsumerController {

    @Autowired
    private ValueAddUserConsumeService valueAddUserConsumeService;

    /**
     * 用户消费-列表
     */
    @RequestMapping("/list")
    public Result list(UserConsumerListDTO dto) {
        dto.setConsumeType(dto.getConsumeType() == null ? 0 : dto.getConsumeType());
        ValueAddUserConsumeListBO bo = new ValueAddUserConsumeListBO();
        BeanUtils.copyProperties(dto, bo);
        return Result.success().data(valueAddUserConsumeService.list(bo));
    }

    /**
     * 用户消费-导出
     */
    @RequestMapping("/export")
    public void export(UserConsumerListDTO dto) {
        dto.setConsumeType(dto.getConsumeType() == null ? 0 : dto.getConsumeType());
        ValueAddUserConsumeListBO bo = new ValueAddUserConsumeListBO();
        BeanUtils.copyProperties(dto, bo);
        valueAddUserConsumeService.export(bo);
    }

    /**
     * 用户消费-折线图
     *
     * @return
     */
    @RequestMapping("/line-chart")
    public Result<List<NameMsgVO>> stat() {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("消费人数", "consumeUserNum");
        cacheMap.put("消费次数", "consumeNum");
        cacheMap.put("消费金额", "moneyAll");
        cacheMap.put("ARPU", "arpu");
        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());
        return Result.success().data(list).msg("获取成功");
    }


    /**
     * 用户消费榜-列表
     */
    @RequestMapping("/rank-list")
    public Result rankList(UserConsumerListDTO dto) {
        dto.setConsumeType(dto.getConsumeType() == null ? 0 : dto.getConsumeType());
        ValueAddUserConsumeListBO bo = new ValueAddUserConsumeListBO();
        BeanUtils.copyProperties(dto, bo);
        return Result.success().data(valueAddUserConsumeService.rankList(bo));
    }


    /**
     * 用户消费榜-导出
     */
    @RequestMapping("/rank-export")
    public void rankExport(UserConsumerListDTO dto) {
        dto.setConsumeType(dto.getConsumeType() == null ? 0 : dto.getConsumeType());
        ValueAddUserConsumeListBO bo = new ValueAddUserConsumeListBO();
        BeanUtils.copyProperties(dto, bo);
        valueAddUserConsumeService.rankExport(bo);
    }
}
